#ifndef _SPELLCHECKER_
#define _SPELLCHECKER_

#include <string>
#include <vector>
#include <iostream>

using namespace std;

#define DLEN 54
const char CODE[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'";

class Node;

class Spellchecker {
public:
    Spellchecker();

    void insert(string);
    int  index(char);
    char get_char(int);

    bool is_word(string);
    vector<string> get_suggestion(string);
    string get_next_w(string);

private:
    Node * _v;

    void insert_aux(Node *, string, unsigned); // recursive function
    vector<string> get_sug_aux(Node * node, string s, int i, string hd, bool crd);
    bool is_word_aux(string, int, Node *);
    string get_first_w(Node *, string);
};


class Node {
public:
  // constructor
  Node();

  bool   is_w(int);
  Node * child(int);

  friend class Spellchecker;
private:
  bool   _is_w[DLEN];
  Node * _child[DLEN];
};


// inlines

inline bool   Node::is_w (int i) { return _is_w[i]; }
inline Node * Node::child(int i) { return _child[i]; }

inline int Spellchecker::index(char x) {
  int inx = x - 'a';
  if (inx<26 && inx>=0) return inx;

  inx = x - 'A';
  if (inx<26 && inx>=0) return inx;

  if (x == '-') return 52;
  if (x == '\'') return 53;

  return -1;
}

inline char Spellchecker::get_char(int i) {
  return CODE[i];
}


#endif
